package com.xbongbong.pro.enums.raiders.enums;

import lombok.Getter;

/**
 * 攻略分数等级枚举
 *
 * @author 徐俊杰
 * @version v1.0
 * @date 2019/9/26 9:54
 * @since v1.0
 */
@Getter
public enum RaidersScoreLevelEnum {
    /**
     * 是否付费枚举，对应数据库内free字段
     */
    LEVEL_1(1, 0, 20),

    LEVEL_2(2, 20, 40),

    LEVEL_3(3, 40, 60),

    LEVEL_4(4, 60, 80),

    LEVEL_5(5, 80, 100),

    /**
     * 六级时前端依然需要5级的分值范围
     */
    LEVEL_6(6, 80, 100),

    ;

    /**
     * 等级
     */
    private final int level;
    /**
     * 等级最低分值
     */
    private final int levelMin;
    /**
     * 等级最高分值
     */
    private final int levelMax;

    RaidersScoreLevelEnum(int level, int levelMin, int levelMax) {
        this.level = level;
        this.levelMin = levelMin;
        this.levelMax = levelMax;
    }

    /**
     * 获取等级
     *
     * @param totalScoreSum 公司总分
     * @return com.xbongbong.pro.enums.raiders.enums.RaidersScoreLevelEnum
     * @author 徐俊杰
     * @date 2019/9/26 10:17
     * @since v1.0
     */
    public static RaidersScoreLevelEnum getLevel(Integer totalScoreSum) {
        RaidersScoreLevelEnum level = LEVEL_1;
        if (totalScoreSum >= LEVEL_1.levelMin && totalScoreSum < LEVEL_1.levelMax) {
            level = LEVEL_1;
        } else if (totalScoreSum >= LEVEL_2.levelMin && totalScoreSum < LEVEL_2.levelMax) {
            level = LEVEL_2;
        } else if (totalScoreSum >= LEVEL_3.levelMin && totalScoreSum < LEVEL_3.levelMax) {
            level = LEVEL_3;
        } else if (totalScoreSum >= LEVEL_4.levelMin && totalScoreSum < LEVEL_4.levelMax) {
            level = LEVEL_4;
        } else if (totalScoreSum >= LEVEL_5.levelMin && totalScoreSum < LEVEL_5.levelMax) {
            level = LEVEL_5;
        } else if (totalScoreSum >= LEVEL_6.levelMax) {
            level = LEVEL_6;
        }
        return level;
    }
}
